<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%;"
      border
      class="tHeight"
      size="mini"
      :default-sort="{prop: formInline.sort, order: formInline.order}"
      @sort-change="tableSortChange"
    >
      <el-table-column
        property="group_name"
        label="班组名称"
        align="center"
      />
      <el-table-column
        property="group_admin"
        label="责任人"
        align="center"
      />
      <el-table-column
        property="telephone"
        label="责任人电话"
        align="center"
      />
      <el-table-column
        label="状态"
        align="center"
      >
        <template slot-scope="scope">
          <!-- eslint-disable-next-line -->
          <el-tag v-if="scope.row.on_status == 0" type="warning">休假</el-tag>
          <el-tag v-if="scope.row.on_status == 1 || scope.row.on_status === null" type="success">空闲</el-tag>
          <el-tag v-if="scope.row.on_status == 2" type="danger">出勤</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <!--   分页   -->
<!--    <el-pagination-->
<!--      style="float: right;"-->
<!--      :page-size="10"-->
<!--      :current-page="formInline.offset"-->
<!--      layout="total, prev, pager, next, jumper"-->
<!--      :total="total"-->
<!--      @size-change="handleSizeChange"-->
<!--      @current-change="handleCurrentChange"-->
<!--    />-->
    <pagination style='float: right;' v-show='total>0' :total='total' :page.sync='formInline.offset' :limit.sync='formInline.limit' @pagination='getList' />
  </div>
</template>

<script>
import { groupList, editGroupStatus } from '@/api/operations'
export default {
  name: 'group',
  data() {
    return {
      total: 0, // 数据总条数
      tableData: [], // 列表数据
      // 搜索表单
      formInline: {
        sort: 'created_at',
        offset: 0,
        limit: 10,
        order: 'ascending',
        group_name: '',
        pageType: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /**
       * @description: 修改人员状态
       * @author: 书童
       */
    addOrEdit(item) {
      editGroupStatus({
        id: item.id,
        on_status: item.on_status === '1' ? 0 : 1
      }).then(res => {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.getList()
      })
    },
    getList() {
      groupList(this.formInline).then(res => {
        this.tableData = res.data.groups
        this.total = res.data.total
      })
    },
    handleSizeChange(val) {
      this.formInline.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.formInline.offset = val
      this.getList()
    },
    /**
       * @description: 排序
       * @author: 书童
       */
    tableSortChange(column) {
      this.formInline.order = column.order ? column.order : 'descending'
      this.formInline.sort = column.prop
      this.formInline.offset = 0
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>

